package com.hdw.job.service;

import com.hdw.common.util.UUIDUtil;
import com.hdw.common.vo.PaginationVO;
import com.hdw.job.api.EtlIndexsqlService;
import com.hdw.job.bean.model.EtlIndexsql;
import com.hdw.job.mapper.EtlIndexsqlMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * etlIndexsql服务实现类
 * Created by hozeData on 2021/07/13.
 */
@Service
@Transactional
public class EtlIndexsqlServiceImpl implements EtlIndexsqlService {

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlIndexsqlServiceImpl.class);

    @Autowired
    private EtlIndexsqlMapper etlIndexsqlMapper;

    @Override
    public int insert(EtlIndexsql etlIndexsql) {
        if(StringUtils.isEmpty(etlIndexsql.getIdIndexsql())){
            String uuid32 = UUIDUtil.getUUID32();
            etlIndexsql.setIdIndexsql(uuid32);
        }
        return etlIndexsqlMapper.insert(etlIndexsql);
    }

    @Override
    public int insertSelective(EtlIndexsql etlIndexsql)  {
        if(StringUtils.isEmpty(etlIndexsql.getIdIndexsql())){
            String uuid32 = UUIDUtil.getUUID32();
            etlIndexsql.setIdIndexsql(uuid32);
        }
        return etlIndexsqlMapper.insertSelective(etlIndexsql);
    }

    @Override
    public int updateByIdSelective(EtlIndexsql etlIndexsql)  {

        return etlIndexsqlMapper.updateByPrimaryKeySelective(etlIndexsql);
    }

    @Override
    public EtlIndexsql getById(String idIndexsql)  {
        return etlIndexsqlMapper.selectByPrimaryKey(idIndexsql);
    }

    @Override
    public List<EtlIndexsql> findByModel(EtlIndexsql etlIndexsql)  {
        return etlIndexsqlMapper.findByModel(etlIndexsql);
    }

    @Override
    public PaginationVO<EtlIndexsql> findPageByModel(EtlIndexsql etlIndexsql, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlIndexsql> quesList = etlIndexsqlMapper.findByModel(etlIndexsql);
        PageInfo<EtlIndexsql> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlIndexsql> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }


}
